<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛 | Vixcity</title><meta name="keywords" content="源码,Vue-devtools,Vue"><meta name="author" content="Vixcity"><meta name="copyright" content="Vixcity"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛准备过程今天我又来看源码了，今天来看 vue-devtools 的源码 我们来看看 github 上 vue-devtools 的源码 我们看到它的 readme 里面有个 Documentation 这个点进去就是他的官网（PS：现在 vue-devtools 也有官网了） 首先点击右上角的 Gride 或者点击中间的 Ge">
<meta property="og:type" content="article">
<meta property="og:title" content="【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛">
<meta property="og:url" content="http://vixcity.gitee.io/my-gitee-blog/2021/09/14/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91%E6%89%8B%E6%91%B8%E6%89%8B%E6%95%99%E4%BD%A0%E8%B0%83%E8%AF%95%20vue-devtools%20%EF%BC%8C%E4%BD%A0%E7%A1%AE%E5%AE%9A%E4%B8%8D%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%98%9B/index.html">
<meta property="og:site_name" content="Vixcity">
<meta property="og:description" content="【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛准备过程今天我又来看源码了，今天来看 vue-devtools 的源码 我们来看看 github 上 vue-devtools 的源码 我们看到它的 readme 里面有个 Documentation 这个点进去就是他的官网（PS：现在 vue-devtools 也有官网了） 首先点击右上角的 Gride 或者点击中间的 Ge">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://vixcity.gitee.io/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg">
<meta property="article:published_time" content="2021-09-13T16:00:00.000Z">
<meta property="article:modified_time" content="2022-01-04T03:04:47.344Z">
<meta property="article:author" content="Vixcity">
<meta property="article:tag" content="源码">
<meta property="article:tag" content="Vue-devtools">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://vixcity.gitee.io/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg"><link rel="shortcut icon" href="/my-gitee-blog/img/favicon.ico"><link rel="canonical" href="http://vixcity.gitee.io/my-gitee-blog/2021/09/14/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91%E6%89%8B%E6%91%B8%E6%89%8B%E6%95%99%E4%BD%A0%E8%B0%83%E8%AF%95%20vue-devtools%20%EF%BC%8C%E4%BD%A0%E7%A1%AE%E5%AE%9A%E4%B8%8D%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%98%9B/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/my-gitee-blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/my-gitee-blog/',
  algolia: undefined,
  localSearch: {"path":"/my-gitee-blog/search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: '/my-gitee-blog/',
      css: '/my-gitee-blog/'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-01-04 11:04:47'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/my-gitee-blog/css/mycss.css"><link rel="stylesheet" href="/my-gitee-blog/css/newStyle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome-animation@1.1.1/css/font-awesome-animation.css"><link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><link rel="stylesheet" href="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/my-gitee-blog/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/archives/"><div class="headline">文章</div><div class="length-num">55</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/tags/"><div class="headline">标签</div><div class="length-num">50</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/my-gitee-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/PicBed"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/my-gitee-blog/">Vixcity</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/my-gitee-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/PicBed"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-09-13T16:00:00.000Z" title="发表于 2021-09-14 00:00:00">2021-09-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-04T03:04:47.344Z" title="更新于 2022-01-04 11:04:47">2022-01-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/my-gitee-blog/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/">大前端</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/my-gitee-blog/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/%E6%BA%90%E7%A0%81/">源码</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.8k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="【源码阅读】手摸手教你调试-vue-devtools-，你确定不来看看嘛"><a href="#【源码阅读】手摸手教你调试-vue-devtools-，你确定不来看看嘛" class="headerlink" title="【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛"></a>【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛</h2><h3 id="准备过程"><a href="#准备过程" class="headerlink" title="准备过程"></a>准备过程</h3><p>今天我又来看源码了，今天来看 vue-devtools 的源码</p>
<p>我们来看看 github 上 vue-devtools 的源码</p>
<p>我们看到它的 readme 里面有个 <a target="_blank" rel="noopener" href="https://devtools.vuejs.org/">Documentation</a></p>
<p>这个点进去就是他的官网（PS：现在 vue-devtools 也有官网了）</p>
<p>首先点击右上角的 Gride 或者点击中间的 Get Star 按钮</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132216417.png" alt="Guide"></p>
<p>点击我们会来到这个界面</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132218919.png" alt="主界面"></p>
<p>这个是安装的界面，我们按照界面提示安装一下</p>
<p>因为我们是要研究这个源码的，所以我们继续往下看</p>
<p>点击到这个 Open component in editor（翻译：在编辑器中打开组件）</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132221479.png" alt="Open component in editor"></p>
<p>点开我们可以看到主页面有这么一段话</p>
<blockquote>
<p>Vue CLI 3 supports this feature out-of-the-box when running <code>vue-cli-service serve</code>.<br>翻译：在运行“vue-cli-service serve”时，Vue CLI 3支持此功能。</p>
</blockquote>
<p>啥意思呢，说人话就是</p>
<p>我们可以在 vue-cli-service serve 的时候，在编辑器中打开组件</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132227239.jpg" alt="点击组件"></p>
<p>当你运行 vue-cli-service serve 的时候，直接就可以开箱即用这个功能</p>
<p>那他是怎么做到的呢？这个就是我们今天要阅读的源码的内容了~</p>
<h3 id="仓库"><a href="#仓库" class="headerlink" title="仓库"></a>仓库</h3><p>首先我们拿一下川神大佬的 git 仓库地址，来开始今天的源码阅读</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/lxchuan12/open-in-editor.git</span><br></pre></td></tr></table></figure>

<p>github 访问速度慢的话可以去<a target="_blank" rel="noopener" href="https://www.dogfight360.com/blog/475/">羽翼城大佬的博客</a></p>
<p>下载软件然后去进行加速</p>
<p>当我们克隆完成之后，我们进入到 vue3-project 去安装依赖</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm install </span><br><span class="line"><span class="comment"># OR </span></span><br><span class="line">yarn</span><br></pre></td></tr></table></figure>

<h3 id="寻找入口-launch-editor-middleware"><a href="#寻找入口-launch-editor-middleware" class="headerlink" title="寻找入口 - launch-editor-middleware"></a>寻找入口 - launch-editor-middleware</h3><p>我们看到官网上有这么一句话</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132248288.png" alt="图片"></p>
<p>我们可以猜测</p>
<p>开箱即用应该和下面这个模块有关系</p>
<p><code>launch-editor-middleware</code></p>
<p>我们去找找看这个模块</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132251755.png" alt="没找到"></p>
<p>我们发现找到的都是在 yarn 里面的，明显和我们的需求不符</p>
<p>众所周知，yarn.lock 是 yarn 安装依赖包的记录</p>
<p>所以我们找到的这个是不对的</p>
<p>我们就可以猜测，这个包是在 node_modules 中的，所以 vscode 会自动忽略</p>
<p>那怎么办呢</p>
<p>我们可以点击…</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132255684.png" alt="..."></p>
<p>我们就可以发现有一个排除的文件的选项，我们点击它的齿轮的图标</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132256997.png" alt="排除的文件"></p>
<p>就会有一大堆的东西出来了，其实点击这个图标是让他去之前忽略的地方去找</p>
<p>此时我们可以发现在这么一大堆的东西里面，有两个可以的目标</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132258697.png" alt="可疑"></p>
<p>现在有两个可疑人物该怎么办呢？</p>
<p>不着急，我们在去官网上看一下</p>
<p>有一个这么个代码段，就在刚才的 <code>launch-editor-middleware</code> 下面</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">app.use(<span class="string">&#x27;/__open-in-editor&#x27;</span>, openInEditor())</span><br></pre></td></tr></table></figure>

<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132301516.png" alt="官网"></p>
<p>那我们就可以在这两个文件里面去进行寻找，看看那个文件有这个代码段的</p>
<h3 id="启动项目"><a href="#启动项目" class="headerlink" title="启动项目"></a>启动项目</h3><p>那他就是符合我们的期望的文件</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132304151.png" alt="serve"></p>
<p>我们可以在 serve.js 里面找到它，那么我们就在这个地方打上断点</p>
<p>我们启动一下项目</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132341295.png" alt="项目启动成功"></p>
<p>项目启动成功</p>
<h4 id="遇到的坑"><a href="#遇到的坑" class="headerlink" title="遇到的坑"></a>遇到的坑</h4><p>如果你发现你的浏览器当中，vue 的图标没有亮起来，像以下这样的话，请检查一下你的 vue-devtools 的版本</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132344769.png" alt="不亮与亮"></p>
<p> 上面左边这个 vue-devtools 是对应的下面左边的那个插件，上面右边对应下面右边的插件</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132346473.png" alt="插件"></p>
<p> 正式版的插件是不会亮的，需要 beta 版本的插件才会亮起来，这是一个小小的坑</p>
<p> vue3 项目需要右边的插件才会亮起来</p>
<h4 id="功能介绍"><a href="#功能介绍" class="headerlink" title="功能介绍"></a>功能介绍</h4><p> 我们点击一下以下地方，他会跳到编辑器</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132351732.png" alt="开始"></p>
<p> 我们发现，点这里刚刚那个断点没进来</p>
<p> 那么我们在进去点击这个函数进到这个函数里面来打断点</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132352202.png" alt="点进去"></p>
<p> 点进去这个标红的函数</p>
<p> 进到这个文件，在该行打上断点</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132354565.png" alt="断点"></p>
<p> 再次点击浏览器的打开文件按钮</p>
<p> 发现成功进到断点里面来了</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109132355684.png" alt="进来了"></p>
<p> 接下来我们就可以愉快的调试了~</p>
<h3 id="开始调试"><a href="#开始调试" class="headerlink" title="开始调试"></a>开始调试</h3><p>首先我们进来上图的位置</p>
<h3 id="launch-editor-middleware"><a href="#launch-editor-middleware" class="headerlink" title="launch-editor-middleware"></a>launch-editor-middleware</h3><p>这个是要在<code>launch-editor-middleware</code>中间件中</p>
<p>最终是调用 <code>launch-editor</code> 打开文件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">launch(path.resolve(srcRoot, file), specifiedEditor, onErrorCallback)</span><br></pre></td></tr></table></figure>

<p>因为 launch 是在 launch-editor 文件里面的</p>
<p>所以我们点击函数名跳转进来该文件，并且打上断点</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109141047648.jpg" alt="文件"></p>
<h3 id="launch-editor"><a href="#launch-editor" class="headerlink" title="launch-editor"></a>launch-editor</h3><p>我们慢慢的一步一步调试</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (!fs.existsSync(fileName)) &#123;</span><br><span class="line"> <span class="comment">// 判断文件是否存在，不存在，直接返回。</span></span><br><span class="line">  <span class="keyword">return</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">typeof</span> specifiedEditor === <span class="string">&#x27;function&#x27;</span>) &#123;</span><br><span class="line"> <span class="comment">// 如果 specifiedEditor =&gt; 这里传递过来的则是函数 </span></span><br><span class="line"> <span class="comment">// 那么和 onErrorCallback 切换下，把它赋值给错误回调函数</span></span><br><span class="line">  onErrorCallback = specifiedEditor</span><br><span class="line">  specifiedEditor = <span class="literal">undefined</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 包裹一层函数</span></span><br><span class="line">onErrorCallback = wrapErrorCallback(onErrorCallback)</span><br><span class="line"><span class="comment">// 猜测当前进程运行的是哪个编辑器</span></span><br><span class="line"><span class="keyword">const</span> [editor, ...args] = guessEditor(specifiedEditor)</span><br><span class="line"><span class="keyword">if</span> (!editor) &#123;</span><br><span class="line">  onErrorCallback(fileName, <span class="literal">null</span>)</span><br><span class="line">  <span class="keyword">return</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="wrapErrorCallback-包裹错误函数回调"><a href="#wrapErrorCallback-包裹错误函数回调" class="headerlink" title="wrapErrorCallback 包裹错误函数回调"></a>wrapErrorCallback 包裹错误函数回调</h4><p>↓这段的代码，就是传递错误回调函数</p>
<p><code>wrapErrorCallback</code> 返回给一个新的函数</p>
<p><code>wrapErrorCallback</code> 执行时，再去执行 onErrorCallback(cb)</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onErrorCallback = wrapErrorCallback(onErrorCallback)</span><br></pre></td></tr></table></figure>

<h4 id="guessEditor-猜测当前正在使用的编辑器"><a href="#guessEditor-猜测当前正在使用的编辑器" class="headerlink" title="guessEditor 猜测当前正在使用的编辑器"></a>guessEditor 猜测当前正在使用的编辑器</h4><p>我们再进去看看他具体是干啥的</p>
<p>先是来了一个判断</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 如果具体指明了编辑器，则解析下返回。</span></span><br><span class="line"><span class="comment">// 如果指定了编辑器，则解析一下，这里没有传入。如果自己指定了路径。 </span></span><br><span class="line"><span class="comment">// 比如 c/Users/lxchu/AppData/Local/Programs/Microsoft VS Code/bin/code </span></span><br><span class="line"><span class="comment">// 会根据空格切割成 c/Users/lxchu/AppData/Local/Programs/Microsoft</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (specifiedEditor) &#123;</span><br><span class="line"> <span class="keyword">return</span> shellQuote.parse(specifiedEditor)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 然后在去调用 node 的原生 api 去看看调用他的平台是哪一个</p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 找出当前进程中哪一个编辑器正在运行。`macOS` 和 `Linux` 用 `ps x` 命令 `windows` 则用 `Get-Process` 命令</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line"> <span class="comment">//  代码有删减</span></span><br><span class="line"> <span class="keyword">if</span> (process.platform === <span class="string">&#x27;darwin&#x27;</span>) &#123;</span><br><span class="line">   <span class="keyword">const</span> output = childProcess.execSync(<span class="string">&#x27;ps x&#x27;</span>).toString()</span><br><span class="line">   <span class="comment">// 省略</span></span><br><span class="line"> &#125; <span class="keyword">else</span> <span class="keyword">if</span> (process.platform === <span class="string">&#x27;win32&#x27;</span>) &#123;</span><br><span class="line">   <span class="keyword">const</span> output = childProcess</span><br><span class="line">  .execSync(<span class="string">&#x27;powershell -Command &quot;Get-Process | Select-Object Path&quot;&#x27;</span>, &#123;</span><br><span class="line">    <span class="attr">stdio</span>: [<span class="string">&#x27;pipe&#x27;</span>, <span class="string">&#x27;pipe&#x27;</span>, <span class="string">&#x27;ignore&#x27;</span>]</span><br><span class="line">  &#125;)</span><br><span class="line">  .toString()</span><br><span class="line">  <span class="comment">// 省略</span></span><br><span class="line"> &#125; <span class="keyword">else</span> <span class="keyword">if</span> (process.platform === <span class="string">&#x27;linux&#x27;</span>) &#123;</span><br><span class="line">   <span class="keyword">const</span> output = childProcess</span><br><span class="line">  .execSync(<span class="string">&#x27;ps x --no-heading -o comm --sort=comm&#x27;</span>)</span><br><span class="line">  .toString()</span><br><span class="line"> &#125;</span><br><span class="line">&#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line"> <span class="comment">// Ignore...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="launch-editor-剩余部分"><a href="#launch-editor-剩余部分" class="headerlink" title="launch-editor 剩余部分"></a>launch-editor 剩余部分</h4><p>接着我们来看他的剩余部分</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> childProcess = <span class="built_in">require</span>(<span class="string">&#x27;child_process&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (process.platform === <span class="string">&#x27;win32&#x27;</span>) &#123;</span><br><span class="line">    <span class="comment">// On Windows, launch the editor in a shell because spawn can only</span></span><br><span class="line">    <span class="comment">// launch .exe files.</span></span><br><span class="line">    _childProcess = childProcess.spawn(</span><br><span class="line">        <span class="string">&#x27;cmd.exe&#x27;</span>,</span><br><span class="line">        [<span class="string">&#x27;/C&#x27;</span>, editor].concat(args),</span><br><span class="line">        &#123; <span class="attr">stdio</span>: <span class="string">&#x27;inherit&#x27;</span> &#125;</span><br><span class="line">    )</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    _childProcess = childProcess.spawn(editor, args, &#123; <span class="attr">stdio</span>: <span class="string">&#x27;inherit&#x27;</span> &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这段代码讲的是</p>
<p>用子进程模块</p>
<p>简单来说子进程模块有着执行命令的能力</p>
<p>原理其实就是利用<code>nodejs</code>中的<code>child_process</code></p>
<p>执行了类似<code>code path/to/file</code>命令</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>一句话简述原理：</p>
<blockquote>
<p>利用nodejs中的child_process，执行了类似code path/to/file命令，于是对应编辑器就打开了相应的文件，而对应的编辑器则是通过在进程中执行ps x（Window则用Get-Process）命令来查找的，当然也可以自己指定编辑器。</p>
</blockquote>
<p>OK，本篇完~</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://vixcity.gitee.io/my-gitee-blog">Vixcity</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://vixcity.gitee.io/my-gitee-blog/2021/09/14/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91%E6%89%8B%E6%91%B8%E6%89%8B%E6%95%99%E4%BD%A0%E8%B0%83%E8%AF%95%20vue-devtools%20%EF%BC%8C%E4%BD%A0%E7%A1%AE%E5%AE%9A%E4%B8%8D%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%98%9B/">http://vixcity.gitee.io/my-gitee-blog/2021/09/14/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91%E6%89%8B%E6%91%B8%E6%89%8B%E6%95%99%E4%BD%A0%E8%B0%83%E8%AF%95%20vue-devtools%20%EF%BC%8C%E4%BD%A0%E7%A1%AE%E5%AE%9A%E4%B8%8D%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%98%9B/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://vixcity.gitee.io/my-gitee-blog" target="_blank">Vixcity</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/my-gitee-blog/tags/%E6%BA%90%E7%A0%81/">源码</a><a class="post-meta__tags" href="/my-gitee-blog/tags/Vue-devtools/">Vue-devtools</a><a class="post-meta__tags" href="/my-gitee-blog/tags/Vue/">Vue</a></div><div class="post_share"><div class="social-share" data-image="/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg" data-sites="wechat,qq"></div><link rel="stylesheet" href="/my-gitee-blog/" media="print" onload="this.media='all'"><script src="/my-gitee-blog/" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/my-gitee-blog/2021/09/15/%E3%80%90JavaScript%E3%80%91%E5%87%A0%E4%B8%AAJavaScript%E6%9E%81%E7%9F%AD%E6%97%A5%E6%9C%9F%E6%97%B6%E9%97%B4%E4%BB%A3%E7%A0%81%E7%89%87%E6%AE%B5%EF%BC%88%E4%BD%A0%E5%80%BC%E5%BE%97%E6%8B%A5%E6%9C%89%EF%BC%89/"><img class="prev-cover" src="/my-gitee-blog/img/JS.jpg" onerror="onerror=null;src='/my-gitee-blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">【JavaScript】几个JavaScript极短日期时间代码片段（你值得拥有）</div></div></a></div><div class="next-post pull-right"><a href="/my-gitee-blog/2021/09/13/%E3%80%90CSS%E3%80%91%E5%85%A8%E5%85%BC%E5%AE%B9%E7%9A%84%E6%AF%9B%E7%8E%BB%E7%92%83%E6%95%88%E6%9E%9C/"><img class="next-cover" src="/my-gitee-blog/img/CSS.jpg" onerror="onerror=null;src='/my-gitee-blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">【CSS杂谈】全兼容的毛玻璃效果</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/my-gitee-blog/2021/10/22/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91Vue-release%20%E5%B0%A4%E9%9B%A8%E6%BA%AA%E5%8F%91%E5%B8%83%20Vue.js%20%E7%9A%84%E6%B5%81%E7%A8%8B%E4%BB%A5%E5%8F%8A%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8F%91%E5%B8%83%E5%8A%9F%E8%83%BD%E7%9A%84%E5%AE%9E%E7%8E%B0/" title="【源码阅读】Vue-release 尤雨溪发布 Vue.js 的流程以及自动化发布功能的实现"><img class="cover" src="/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-22</div><div class="title">【源码阅读】Vue-release 尤雨溪发布 Vue.js 的流程以及自动化发布功能的实现</div></div></a></div><div><a href="/my-gitee-blog/2021/10/20/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91koa%E6%B4%8B%E8%91%B1%E6%A8%A1%E5%9E%8B%E4%B8%8Ekoa-compose/" title="【源码阅读】koa洋葱模型与koa-compose"><img class="cover" src="/my-gitee-blog/img/NodeJs.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-20</div><div class="title">【源码阅读】koa洋葱模型与koa-compose</div></div></a></div><div><a href="/my-gitee-blog/2021/10/23/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91update-notifier%20%E6%9B%B4%E6%96%B0%20CLI%20%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%9A%84%E9%80%9A%E7%9F%A5-%E8%AF%A6%E8%A7%A3/" title="【源码阅读】update-notifier 更新 CLI 应用程序的通知-详解"><img class="cover" src="/my-gitee-blog/img/NodeJs.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-23</div><div class="title">【源码阅读】update-notifier 更新 CLI 应用程序的通知-详解</div></div></a></div><div><a href="/my-gitee-blog/2021/10/25/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91validate-npm-package-name%20%E9%AA%8C%E8%AF%81%E6%98%AF%E5%90%A6%E6%98%AF%E4%B8%AA%E6%9C%89%E6%95%88%E7%9A%84%20npm%20%E5%8C%85%E5%90%8D/" title="【源码阅读】validate-npm-package-name 验证是否是个有效的 npm 包名"><img class="cover" src="/my-gitee-blog/img/NodeJs.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-25</div><div class="title">【源码阅读】validate-npm-package-name 验证是否是个有效的 npm 包名</div></div></a></div><div><a href="/my-gitee-blog/2021/10/19/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91co.js%20-%20%E8%AE%A9%E5%BC%82%E6%AD%A5%E7%9A%84%E4%BB%A3%E7%A0%81%E5%90%8C%E6%AD%A5%E5%8C%96/" title="【源码阅读】co.js - 让异步的代码同步化"><img class="cover" src="/my-gitee-blog/img/JS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-19</div><div class="title">【源码阅读】co.js - 让异步的代码同步化</div></div></a></div><div><a href="/my-gitee-blog/2021/10/15/%E3%80%90NodeJS%E3%80%91Node.js%20+%20Vue%20%E5%AE%9E%E7%8E%B0%20Excel%20%E5%AF%BC%E5%87%BA%E4%B8%8E%E4%BF%9D%E5%AD%98/" title="【NodeJS】Node.js + Vue 实现 Excel 导出与保存"><img class="cover" src="/my-gitee-blog/img/NodeJs.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-15</div><div class="title">【NodeJS】Node.js + Vue 实现 Excel 导出与保存</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81NDQ0NS8zMDkxNg=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/my-gitee-blog/img/avatar.png" onerror="this.onerror=null;this.src='/my-gitee-blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Vixcity</div><div class="author-info__description">今日事，今日毕</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/my-gitee-blog/archives/"><div class="headline">文章</div><div class="length-num">55</div></a></div><div class="card-info-data-item is-center"><a href="/my-gitee-blog/tags/"><div class="headline">标签</div><div class="length-num">50</div></a></div><div class="card-info-data-item is-center"><a href="/my-gitee-blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/Vixcity"><i class="fab fa-github"></i><span>我的Github</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/Vixcity" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:2091283625@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是Vixcity目前的小博客</div></div><div class="sticky_layout"><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden;"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%;"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/13/%E3%80%90NodeJS%E3%80%91NodeJS%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%AF%B7%E6%B1%82/" title="【NodeJS】NodeJS 服务端请求"><img src="/my-gitee-blog/img/NodeJs.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【NodeJS】NodeJS 服务端请求"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/13/%E3%80%90NodeJS%E3%80%91NodeJS%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%AF%B7%E6%B1%82/" title="【NodeJS】NodeJS 服务端请求">【NodeJS】NodeJS 服务端请求</a><time datetime="2022-07-12T16:00:00.000Z" title="发表于 2022-07-13 00:00:00">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%201/" title="【Hexo】标签样式列表参考 - 1"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 1"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%201/" title="【Hexo】标签样式列表参考 - 1">【Hexo】标签样式列表参考 - 1</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%202/" title="【Hexo】标签样式列表参考 - 2"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 2"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%202/" title="【Hexo】标签样式列表参考 - 2">【Hexo】标签样式列表参考 - 2</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%203/" title="【Hexo】标签样式列表参考 - 3"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 3"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%203/" title="【Hexo】标签样式列表参考 - 3">【Hexo】标签样式列表参考 - 3</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/07/%E3%80%90NodeJS%E3%80%91NodeJS%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="【NodeJS】NodeJS入门学习"><img src="/my-gitee-blog/img/NodeJs.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【NodeJS】NodeJS入门学习"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/07/%E3%80%90NodeJS%E3%80%91NodeJS%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="【NodeJS】NodeJS入门学习">【NodeJS】NodeJS入门学习</a><time datetime="2022-07-06T16:00:00.000Z" title="发表于 2022-07-07 00:00:00">2022-07-07</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Vixcity</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div id="running-time"></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/my-gitee-blog/js/utils.js"></script><script src="/my-gitee-blog/js/main.js"></script><script src="/my-gitee-blog/js/tw_cn.js"></script><script src="/my-gitee-blog/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !false) {
  if (false) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/my-gitee-blog/js/newStyle.js"></script><script src="/my-gitee-blog/js/sakura.js"></script><script>setInterval(()=>{let create_time=Math.round(new Date("2021-9-8-00:00:00").getTime()/1000);let timestamp=Math.round((new Date().getTime()+8*60*60*1000)/1000);let second=timestamp-create_time;let time=new Array(0,0,0,0,0);if(second>=365*24*3600){time[0]=parseInt(second/(365*24*3600));second%=365*24*3600}if(second>=24*3600){time[1]=parseInt(second/(24*3600));second%=24*3600}if(second>=3600){time[2]=parseInt(second/3600);second%=3600}if(second>=60){time[3]=parseInt(second/60);second%=60}if(second>0){time[4]=second}currentTimeHtml='小博客已经安全运行 '+time[0]+' 年 '+time[1]+' 天 '+time[2]+' 时 '+time[3]+' 分 '+time[4]+' 秒';var elementById=document.getElementById('running-time');if(elementById){elementById.innerHTML=currentTimeHtml}},1000);</script><script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script><script src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img id="card-clock-loading" src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-clock/clock/images/weather/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading" class="entered loading"></div></div></div></div></div>';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '0.5s');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><!-- hexo injector body_end end --><script src="/my-gitee-blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>